// 权限管理工具
import router from "./router"
import { getToken } from "./utils/auth"
import NProgress from "nprogress"
import 'nprogress/nprogress.css'

// 关闭进度条的选择
NProgress.configure({ showSpinner: false })
//路由守卫
//路由白名单
const whiteList = ['/login','/404']
// 前置守卫
router.beforeEach((to,from,next)=>{
    NProgress.start()
    // 判断有无token
    const token = getToken()
    if(token){
        // 判断去的是否是登录页
        if(to.path==='/login'){
            next('/')//去首页
        }else{
            next()//放行
        }
    }else{
        // 判断是否在白名单

        if(whiteList.includes(to.path)){
            next()
        }else{
            next('/login')
        }
    }
})
// 后置守卫
router.afterEach((to,from)=>{
    NProgress.done()
    document.title = to.meta.title || '黑马智数'
})
